共计 2063 个字符,预计需要花费 6 分钟才能阅读完成。
前言
发现在集群的master上执行kubectl可以自动补全,而在远程server通过指定kubeconfig时无法实现自动补全。
应该是安装集群时,相关剧本已经将自动补全给实现了。下面探索下如何进行手动配置。
安装kubectl
进入官网,选择对应版本下载。
ansible @ops-2701 /tmp$ curl -LO https://dl.k8s.io/release/v1.22.16/bin/linux/amd64/kubectl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 138 100 138 0 0 138 0 0:00:01 --:--:-- 0:00:01 607
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
HTTPS-proxy has similar options --proxy-cacert and --proxy-insecure.
60 ansible @ops-2701 /tmp$ curl -LO https://dl.k8s.io/release/v1.22.16/bin/linux/amd64/kubectl -k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 138 100 138 0 0 138 0 0:00:01 --:--:-- 0:00:01 607
100 44.7M 100 44.7M 0 0 935k 0 0:00:49 0:00:49 --:--:-- 1178k
可以看到,官方文档提供的文件链接ssl证书过期了,加上-k
参数忽略ssl校验。
校验版本,结果符合预期
ansible @ops-2701 /tmp$ chmod +x kubectl
ansible @ops-2701 /tmp$ ./kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.16", GitCommit:"b28e1f370a4a4c428ddbeababcaf0198f048fcac", GitTreeState:"clean", BuildDate:"2022-11-09T13:37:37Z", GoVersion:"go1.16.15", Compiler:"gc", Platform:"linux/amd64"}
移动至环境变量目录
ansible @ops-2701 /tmp$ sudo mv kubectl /bin/kubectl
配置自动补全
安装bash-completion
Ubuntu 和 CentOS都可以用默认的包管理源进行安装
# Ubuntu
apt-get update
apt-get install bash-completion -y
# CentOS
yum install bash-completion -y
查看当前completion
存在的配置
# ls /etc/bash_completion.d/
git iprutils redefine_filedir scl.bash yum-utils.bash
增加kubectl配置到completion
配置目录中
kubectl completion bash > /etc/bash_completion.d/kubectl
重新登录 ssh 会话即可生效自动补齐
本文属于专题:Kubernetes
- Ubuntu20.04 安装 nvidia 驱动
- 使用 kubeadm 安装 k8s 集群
- kubectl 配置自动补全
引用链接
正文完
2023-08-03